package com.base.myproject.client.HR.Self;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.LasyObejct;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Label;

public class SelfBcode_Family extends LayoutContainer implements LasyObejct {

	BaseStore<BusiObject> mainstore = null;

	public SelfBcode_Family(BaseStore<BusiObject> mainstore) {
		this.mainstore = mainstore;
		init();
	}

	public void init() {
		initWidget();
	}
	
	public void initWidget(){
		FieldSet fs1 = new FieldSet();
		FieldSet fs2 = new FieldSet();
		FieldSet fs3 = new FieldSet();
		
		 fs1.add(createbcode_Spouse_Form());
		 fs2.add(create_bcode_famify_Grid());
		 fs3.add(create_bcode_contact_Grid());
		// fs4.add(create_bcode_cer_Grid());

		fs1.setHeading("配偶");
		fs2.setHeading("家庭成员");
		fs3.setHeading("紧急联络方式");


		VerticalPanel v = new VerticalPanel();
		v.add(fs1);
		v.add(fs2);
		v.add(fs3);
	
		this.add(v);
	}
	
	BaseStore<BusiObject> bcode_Spouse_store = null;

	BaseStore<BusiObject> get_bcode_Spouse_Store() {
		if (bcode_Spouse_store == null) {
			create_bcode_Spouse_Store();
		}
		return bcode_Spouse_store;
	}

	BaseStore<BusiObject> create_bcode_Spouse_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("Spouse_cnname");
		type.getField("Spouse_cnname").setType(String.class);
		type.addField("Spouse_enname");
		type.getField("Spouse_enname").setType(String.class);
		type.addField("idcard");
		type.getField("idcard").setType(String.class);
		type.addField("Nationality");
		type.getField("Nationality").setType(String.class);
		type.addField("PassportNo");
		type.getField("PassportNo").setType(String.class);
		type.addField("PassportIssueCountry");
		type.getField("PassportIssueCountry").setType(String.class);
		type.addField("PassportIssueDate");
		type.getField("PassportIssueDate").setType(Date.class);
		type.addField("Occupation");
		type.getField("Occupation").setType(String.class);
		type.addField("Company");
		type.getField("Company").setType(String.class);
		type.addField("MedicalPlanID");
		type.getField("MedicalPlanID").setType(String.class);
		type.addField("DentalPlanID");
		type.getField("DentalPlanID").setType(String.class);
		type.addField("JobPosition");
		type.getField("JobPosition").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_Spouse");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from bcode_Spouse where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });//
		// 关联主表字段
		bcode_Spouse_store = new BaseStore<BusiObject>(type, info);
		return bcode_Spouse_store;
	}

	BaseFormPanel bcode_Spouse_form = null;

	BaseFormPanel createbcode_Spouse_Form() {
		BaseFormPanel form = new BaseFormPanel(get_bcode_Spouse_Store(),false);
		TableLayout tl = new TableLayout(8);

		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		form.setLayout(tl);
		form.setHeaderVisible(false);

		form.add(new Label("配偶中文名称:"), td);
		TextField<String> C_num3 = new TextField<String>();
		C_num3.setName("Spouse_cnname");
		C_num3.setReadOnly(true);
		form.add(C_num3, td);
		
		form.add(new Label("配偶英文名称:"), td);
		TextField<String> C_num4 = new TextField<String>();
		C_num4.setReadOnly(true);
		C_num4.setName("Spouse_enname");
		form.add(C_num4, td);
		
		form.add(new Label("身份证号:"), td);
		TextField<String> C_num5 = new TextField<String>();
		C_num5.setReadOnly(true);
		C_num5.setName("idcard");
		form.add(C_num5, td);
		form.add(new Label("国籍:"), td);
		TextField<String> C_num6 = new TextField<String>();
		C_num6.setReadOnly(true);
		C_num6.setName("Nationality");
		form.add(C_num6, td);
		
		form.add(new Label("护照编码:"), td);
		TextField<String> C_num7 = new TextField<String>();
		C_num7.setName("PassportNo");
		form.add(C_num7, td);
		
		form.add(new Label("护照签发国家:"), td);
		TextField<String> C_num8 = new TextField<String>();
		C_num8.setReadOnly(true);
		C_num8.setName("PassportIssueCountry");
		form.add(C_num8, td);
		
		form.add(new Label("护照签发日期:"), td);
		DateField C_data9 = new DateField();
		C_data9.getPropertyEditor().setFormat(
				DateTimeFormat.getFormat("yyyy-M-d"));
		C_data9.setReadOnly(true);
		C_data9.setName("PassportIssueDate");
		form.add(C_data9, td);
		
		form.add(new Label("职业:"), td);
		TextField<String> C_num10 = new TextField<String>();
		C_num10.setReadOnly(true);
		C_num10.setName("Occupation");
		form.add(C_num10, td);
		
		form.add(new Label("公司:"), td);
		TextField<String> C_num11 = new TextField<String>();
		C_num11.setReadOnly(true);
		C_num11.setName("Company");
		form.add(C_num11, td);
		
		form.add(new Label("医疗保健计划:"), td);
		TextField<String> C_num12 = new TextField<String>();
		C_num12.setReadOnly(true);
		C_num12.setName("MedicalPlanID");
		form.add(C_num12, td);
		
		form.add(new Label("牙科保健计划:"), td);
		TextField<String> C_num13 = new TextField<String>();
		C_num13.setName("DentalPlanID");
		C_num13.setReadOnly(true);
		form.add(C_num13, td);
		
		form.add(new Label("工作职位:"), td);
		TextField<String> C_num14 = new TextField<String>();
		C_num14.setReadOnly(true);
		C_num14.setName("JobPosition");
		form.add(C_num14, td);
		form.setReadOnly(true);
		form.inited(126);
		return form;
	};

	BaseStore<BusiObject> bcode_famify_store = null;

	BaseStore<BusiObject> get_bcode_famify_Store() {
		if (bcode_famify_store == null) {
			create_bcode_famify_Store();
		}
		return bcode_famify_store;
	}

	BaseStore<BusiObject> create_bcode_famify_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("ChineseName");
		type.getField("ChineseName").setType(String.class);
		type.addField("englishname");
		type.getField("englishname").setType(String.class);
		type.addField("Relationship");
		type.getField("Relationship").setType(String.class);
		type.addField("Birthday");
		type.getField("Birthday").setType(Date.class);
		type.addField("sex");
		type.getField("sex").setType(String.class);
		type.addField("Nationality");
		type.getField("Nationality").setType(String.class);
		type.addField("PassportNo");
		type.getField("PassportNo").setType(String.class);
		type.addField("PassportIssueCountry");
		type.getField("PassportIssueCountry").setType(String.class);
		type.addField("PassportIssueDate");
		type.getField("PassportIssueDate").setType(Date.class);  //数据库要修改这个字段
		type.addField("Occupation");
		type.getField("Occupation").setType(String.class);
		type.addField("Company");
		type.getField("Company").setType(String.class);
		type.addField("JobPosition");
		type.getField("JobPosition").setType(String.class);
		type.addField("MedicalPlanID");
		type.getField("MedicalPlanID").setType(String.class);
		type.addField("DentalPlanID");
		type.getField("DentalPlanID").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_famify");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from bcode_famify where bcode='{bcode}'");
		info.setParent(mainstore);// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode" });//
		// 关联主表字段
		bcode_famify_store = new BaseStore<BusiObject>(type, info);
		return bcode_famify_store;
	}

	BaseGridPanel bcode_famify_grid = null;

	BaseGridPanel create_bcode_famify_Grid() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

		ColumnConfig C3 = new ColumnConfig("ChineseName", "中文名", 80);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("englishname", "英文名称", 80);
		columns.add(C4);
		ColumnConfig C5 = new ColumnConfig("Relationship", "关系", 80);
		
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("Birthday", "生日", 80);
		DateField dateField6 = new DateField();  
	    dateField6.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C6.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("sex", "性别", 80);
		columns.add(C7);
		ColumnConfig C8 = new ColumnConfig("Nationality", "国籍", 80);
		columns.add(C8);
		ColumnConfig C9 = new ColumnConfig("PassportNo", "护照编码", 80);
		columns.add(C9);
		ColumnConfig C10 = new ColumnConfig("PassportIssueCountry",
				"护照发出地", 80);
		columns.add(C10);
		ColumnConfig C11 = new ColumnConfig("PassportIssueDate",
				"护照发出日期", 80);
		DateField dateField11 = new DateField();  
	    dateField11.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));  
	    C11.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C11);
		ColumnConfig C12 = new ColumnConfig("Occupation", "职业", 80);
		columns.add(C12);
		ColumnConfig C13 = new ColumnConfig("Company", "公司", 80);
		columns.add(C13);
		ColumnConfig C14 = new ColumnConfig("JobPosition", "职位", 80);
		columns.add(C14);
		ColumnConfig C15 = new ColumnConfig("MedicalPlanID", "医疗保健计划",
				80);
		columns.add(C15);
		ColumnConfig C16 = new ColumnConfig("DentalPlanID", "牙科保健计划", 80);
		columns.add(C16);

		ColumnModel cm = new ColumnModel(columns);
		bcode_famify_grid = new BaseGridPanel(get_bcode_famify_Store(), cm);
		bcode_famify_grid.getBg().setHeight(200);
		return bcode_famify_grid;
	}

	BaseStore<BusiObject> bcode_contact_store = null;

	BaseStore<BusiObject> getStore() {
		if (bcode_contact_store == null) {
			create_bcode_contact_Store();
		}
		return bcode_contact_store;
	}

	BaseStore<BusiObject> create_bcode_contact_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("enname");
		type.getField("enname").setType(String.class);
		type.addField("cnname");
		type.getField("cnname").setType(String.class);
		type.addField("tel");
		type.getField("tel").setType(String.class);
		type.addField("Relationship");
		type.getField("Relationship").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("bcode_contact");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from bcode_contact where bcode ='{bcode}'");
		 info.setParent(mainstore);// 关联主表
		 info.setLinkparentcolumns(new String[] { "bcode" }); // 关联主表字段
		 info.setLinkparent_chile_columns(new String[] { "bcode" });//
		// 关联主表字段
		bcode_contact_store = new BaseStore<BusiObject>(type, info);
		return bcode_contact_store;
	}

	BaseGridPanel bcode_contact_grid=null;
	BaseGridPanel create_bcode_contact_Grid() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

		ColumnConfig C3 = new ColumnConfig("enname", "英文名称", 80);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("cnname", "中文名称", 80);
		columns.add(C4);
		ColumnConfig C5 = new ColumnConfig("tel", "电话", 80);
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("Relationship", "关系", 80);
		BaseComboBoxX bc6 = new BaseComboBoxX("name","dictionary", "where type='hr_relationship'");
		columns.add(C6);

		ColumnModel cm = new ColumnModel(columns);
		bcode_contact_grid = new BaseGridPanel(getStore(), cm);
		bcode_contact_grid.getBg().setHeight(200);
		return bcode_contact_grid;
	}

	@Override
	public boolean isopen() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean open() {
		// TODO Auto-generated method stub
		return false;
	}

}
